<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.realName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.username"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="级别">
              <el-select v-model="form.roleId" placeholder="请选择" clearable>
                <el-option v-for="item in roleOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="原上级手机号">
              <el-input v-model="form.oldUsername"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="新上级手机号">
              <el-input v-model="form.newUsername"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="修改时间" width="236">
              <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="dates" type="daterange" range-separator="-"
                start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
              <el-button v-if="hasPermission('AdminUserRecommendProvider.dealRelation')" type="primary" @click="toRoutes('designerInfoRelationEdit')">修改关系</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="realname" label="姓名">
        </el-table-column>
        <el-table-column prop="username" label="手机号">
           <template slot-scope="scope">
            <span>{{scope.row.username | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column label="原上级信息">
          <template slot-scope="scope">
            {{scope.row.oldRealname}}<br>{{scope.row.oldUsername| phonereg}}
          </template>
        </el-table-column>
        <el-table-column label="新上级信息">
          <template slot-scope="scope">
            {{scope.row.newRealname}}<br>{{scope.row.newUsername| phonereg}}
          </template>
        </el-table-column>
        <el-table-column prop="oldRefereeSource" label="原上级绑定来源">
        </el-table-column>
        <el-table-column prop="isWithTeam" label="修改类型">
          <template slot-scope="scope">
            {{scope.row.isWithTeam | isWithTeam}}
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="团队电话">
            <template slot-scope="scope">
            修改前：{{scope.row.oldTeamPhone| phonereg}}<br>修改后：{{scope.row.newTeamPhone| phonereg}}
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注">
        </el-table-column>
        <el-table-column prop="adminName" label="操作员">
        </el-table-column>
        <el-table-column prop="updatedAt" label="修改时间">
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="form.pageNum" :page-sizes="page_sizes" :page-size="form.limit"
            layout="total, sizes, prev, pager, next, jumper" :total="page_totals">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getList } from "@/api/designerInfo";
export default {
  name: "designerInfoRelation",
  data() {
    return {
      value: "1",
      tableLoading: true,
      dates: [],
      form: {
        realName: "",
        username: "",
        roleId: null,
        oldUsername: "",
        newUsername: "",
        updateAtStart: "",
        updateAtEnd: "",
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      roleOptions: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(String(e));
    },
    isWithTeam(e) {
      if (e == 0) {
        return "带团队";
      } else {
        return "不带团队";
      }
    }
  },
  mounted() {
    this.roleOptions = window.helper.roleFn("listReturn");
    this.roleOptions.forEach(item=>{
      item.value = +item.value
    })
    this.getList(this.form);
    //获取级别
    
  },
  methods: {
    // 按钮权限
    hasPermission(e){
        return window.helper.hasPermission(e)
    },
    //成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    //失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    //列表数据获取
    getList(e) {
      this.tableLoading = true;
      let datas = e;
      getList(datas)
        .then(res => {
          console.log(res);
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
            
            // if (this.form.roleId) {
            //   this.form.roleId = this.form.roleId.toString();
            // } else {
            //   this.form.roleId = null;
            // }
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if(this.form.roleId){
        this.form.roleId = Number(this.form.roleId);
      }
      if (this.dates != null) {
        if (this.dates.length) {
          this.form.updateAtStart = this.dates[0];
          this.form.updateAtEnd = this.dates[1];
        }
      } else {
        this.form.updateAtStart = "";
        this.form.updateAtEnd = "";
      }
      this.getList(this.form);
      console.log(this.form);
      console.log(JSON.stringify(this.form));
    },
    // 路由跳转
    toRoutes(e, userId) {
      let route = { name: e, query: { userId: userId } };
      this.$router.push(route);
    },
    //改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    //选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
